package com.studyinghome.config;

import cn.hutool.core.util.RandomUtil;
import lombok.Data;
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;

import java.util.Properties;

/**
 * @author Leslie
 * @create 2023-02-15 14:39
 **/
@Data
public final class RandomShardingKeyGenerator implements ShardingKeyGenerator {

    private Properties properties = new Properties();

    /**
     * 自定义的生成方案类型
     */
    @Override
    public String getType() {
        return "RANDOM";
    }

    /**
     * 核心方法-生成主键ID
     */
    @Override
    public Comparable<?> generateKey() {
        return RandomUtil.randomInt(10000, 100000);
    }
}
